package practice1_100;

import java.util.*;

public class Haha {
    public static void main(String[] args) {
       Haha haha=new Haha();
       ListNode a= haha.deleteDuplication(new ListNode(1,new ListNode(1,new ListNode(2,new ListNode(2,new ListNode(3,new ListNode(3)))))));
        System.out.println(a);

    }

    public ListNode deleteDuplication(ListNode pHead) {
        if(pHead==null) return pHead;
        Set<Integer> set=new HashSet<>();
        ListNode temp=pHead;
        while (temp!=null){
            set.add(temp.val);temp=temp.next;
        }
        temp=new ListNode(0,pHead);
        ListNode tempH=temp;
        while (pHead!=null){
            if(set.contains(pHead.val)){
                temp.next=pHead.next;
                pHead=temp.next;
            }else {
                temp=temp.next;
                pHead=pHead.next;
            }
        }
        return tempH.next;
    }
    public ListNode deleteDuplication1(ListNode pHead) {
        ListNode temp=pHead;
        while (temp!=null){
            ListNode next=temp;
            while (next.next!=null){
                if(next.next.val==temp.val)next.next=next.next.next;
                else next=next.next;
            }
            temp=temp.next;
        }
        return pHead;
    }
}
